package com.techstar.ats.codec.history.decoder;

import io.netty.buffer.ByteBuf;
import com.techstar.ats.codec.DateTimeCodec;
import com.techstar.ats.codec.Decoder;
import com.techstar.ats.dxp.history.F22InusedRecord;
import com.techstar.ats.type.DirectionType;
import com.techstar.ats.type.StoreType;

public enum F22InusedRecordDecoder implements Decoder<F22InusedRecord> {
	INSTANCE;

	public F22InusedRecord create() {
		return new F22InusedRecord();
	}

	public void decode(ByteBuf buf, F22InusedRecord value) {
		value.station = buf.readUnsignedShort();
		value.platform = buf.readUnsignedShort();
		value.arriveTime = DateTimeCodec.INSTANCE.get(buf);
		value.departTime = DateTimeCodec.INSTANCE.get(buf);
		value.store = StoreType.NONE;
		int flag = buf.readUnsignedShort();
		if(0 != (flag & 16)) {
			value.store = StoreType.OUT;
		}

		if(0 != (flag & 32)) {
			value.store = StoreType.IN;
		}

		value.dir = 0 != (flag & 64) ? DirectionType.DN : DirectionType.UP;
		buf.skipBytes(4);
	}
}
